package com.pxmeta.circle.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pxmeta.circle.entity.Circle;
import com.pxmeta.circle.entity.UserCircle;
import com.pxmeta.user.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户圈子表 Mapper 接口
 * </p>
 *
 * @author wcl
 * @since 2022-05-14
 */
public interface UserCircleMapper extends BaseMapper<UserCircle> {

    List<User> getAdminUserByCircleId(@Param("circleId") Long circleId);

    @Select("select c.*, ((SELECT count(1) from kt_mail where circle_id = c.id and target_user_id = uc.user_id and is_del = 0 and is_view = 0) > 0) isRead from kt_user_circle uc right join kt_circle c on uc.circle_id = c.id where uc.is_del = 0  and c.id != 1 and uc.user_id = #{userId} order by uc.sort desc ,uc.create_time desc")
    List<Circle> getUserCircle(@Param("userId") Long userId);

    @Select("SELECT count(1) from kt_user_circle uc right join kt_user u on u.id=uc.user_id where uc.is_del = 0 and u.is_del = 0 and uc.circle_id = #{circleId} ")
    Long getCircleUserCount(@Param("circleId") Long circleId);

    List<User> getUserListBySex(@Param("circleId") Long circleId, @Param("sex") Integer sex);
}
